<template>
  <div id="profile">
    <nav-bar class="nav-bar"><div slot="center">我的商城</div></nav-bar>
    <user-info @click.native="btn" :detail="detail"></user-info>
    <section class="account" v-if="Object.keys(detail).length !== 0">
      <div class="account-item">
        <div class="number">
          <span class="balance">{{ detail.balance }}</span
          >元
        </div>
        <div class="account-info">我的余额</div>
      </div>
      <div class="account-item">
        <div class="number">
          <span class="balance">{{ detail.coupon }}</span
          >个
        </div>
        <div class="account-info">我的优惠</div>
      </div>
      <div class="account-item">
        <div class="number">
          <span class="balance">{{ detail.integral }}</span
          >分
        </div>
        <div class="account-info">我的积分</div>
      </div>
    </section>

    <!--3.封装成一个整体-->
    <list-view :list-data="orderList" class="order-list"></list-view>
    <list-view :list-data="serviceList" class="service-list"></list-view>
  </div>
</template>

<script>
import UserInfo from "./children/UserInfo";
import ListView from "./children/ListView";
import NavBar from "common/navbar/NavBar";
import {getdetail } from "network/profile";
export default {
  name: "Profile",
  components: {
    UserInfo,
    ListView,
    NavBar,
  },
  data: function () {
    return {
      orderList: [
        { icon: "#order", iconColor: "#ff8198", info: "我的消息" },
        { icon: "#point", iconColor: "#fc7b53", info: "积分商城" },
        { icon: "#vip", iconColor: "#ffc636", info: "会员卡" },
      ],
      serviceList: [
        { icon: "#service", iconColor: "#ff8198", info: "我的购物车" },
        { icon: "#download", iconColor: "#ff8198", info: "下载购物APP" },
      ],
      token: "",
      account: "",
      detail: {},
    };
  },
  mounted: function () {},
  created() {
    this._getdetail();
  },
  methods: {
    btn() {
      this.$router.push({ path: "/login" });
    },

    _getdetail() {
      let token = sessionStorage.getItem('token')
      let account = sessionStorage.getItem('account')
      if (!token||!account) {
        return
      }
      else{
        getdetail(token,account).then((res) => {
          console.log(res);
        this.detail = res;
      });
      }

    },
  },
};
</script>

<style scoped>
#profile {
  background-color: #f2f2f2;
}

.nav-bar {
  background-color: var(--color-tint);
  font-weight: 700;
  color: #fff;
}

.account {
  display: flex;
}

.account-item {
  width: 100%;
  background-color: #fff;
  margin-right: 1px;
  text-align: center;
}

.account-item:last-of-type {
  margin-right: 0;
}

.account-item {
  color: #666;
  font-size: 13px;
  padding: 18px;
}

.account-item .balance {
  font-size: 24px;
  font-weight: 700;
  color: #ff5f3e;
}

.account-info {
  margin-top: 6px;
}

.order-list,
.service-list {
  margin-top: 12px;
}
</style>
